using Microsoft.Extensions.Logging;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace DesktopHelper.ViewModels
{
    public class SettingsViewModel : INotifyPropertyChanged
    {
        private readonly ILogger<SettingsViewModel> _logger;

        // 基本设置
        private bool _autoStart;
        private bool _startMinimized;
        private bool _enableClipboardMonitoring = true;
        private int _maxHistoryItems = 1000;
        private int _autoCleanupDays = 30;

        // 快捷键设置
        private bool _enableGlobalHotkeys = true;
        
        // 截图设置
        private string _screenshotFormat = "PNG";
        private int _jpegQuality = 95;
        private double _defaultOpacity = 1.0;
        private bool _alwaysOnTop = true;
        private bool _rememberPosition = true;

        public bool AutoStart
        {
            get => _autoStart;
            set => SetProperty(ref _autoStart, value);
        }

        public bool StartMinimized
        {
            get => _startMinimized;
            set => SetProperty(ref _startMinimized, value);
        }

        public bool EnableClipboardMonitoring
        {
            get => _enableClipboardMonitoring;
            set => SetProperty(ref _enableClipboardMonitoring, value);
        }

        public int MaxHistoryItems
        {
            get => _maxHistoryItems;
            set => SetProperty(ref _maxHistoryItems, value);
        }

        public int AutoCleanupDays
        {
            get => _autoCleanupDays;
            set => SetProperty(ref _autoCleanupDays, value);
        }

        public bool EnableGlobalHotkeys
        {
            get => _enableGlobalHotkeys;
            set => SetProperty(ref _enableGlobalHotkeys, value);
        }

        public string ScreenshotFormat
        {
            get => _screenshotFormat;
            set => SetProperty(ref _screenshotFormat, value);
        }

        public int JpegQuality
        {
            get => _jpegQuality;
            set => SetProperty(ref _jpegQuality, value);
        }

        public double DefaultOpacity
        {
            get => _defaultOpacity;
            set => SetProperty(ref _defaultOpacity, value);
        }

        public bool AlwaysOnTop
        {
            get => _alwaysOnTop;
            set => SetProperty(ref _alwaysOnTop, value);
        }

        public bool RememberPosition
        {
            get => _rememberPosition;
            set => SetProperty(ref _rememberPosition, value);
        }

        public SettingsViewModel(ILogger<SettingsViewModel> logger)
        {
            _logger = logger;
        }

        public event PropertyChangedEventHandler? PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        protected bool SetProperty<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
        {
            if (System.Collections.Generic.EqualityComparer<T>.Default.Equals(field, value))
                return false;

            field = value;
            OnPropertyChanged(propertyName);
            return true;
        }
    }
}